package com.itheima.objectDemo;

import com.google.gson.Gson;

public class CloneDemo2 {
    public static void main(String[] args) throws CloneNotSupportedException {
        int[] data = {1,2,3,4,5};
        UserNew usr1 = new UserNew("zhangsan", "1234", 1, data);
        System.out.println(usr1);

        UserNew usr2 = (UserNew) usr1.clone();
        System.out.println(usr2);

        data[0] = 10;
        System.out.println(usr1);// [10,2,3,4,5]
        System.out.println(usr2);// [1,2,3,4,5]

        // 第三方工具
        Gson gson = new Gson();
        // 把对象转成字符串
        String s = gson.toJson(usr1);
        // 从字符串转回对象
        UserNew usr3 = gson.fromJson(s, UserNew.class);
        System.out.println(usr3);
    }
}
